
//
//  BSBFriendController.m
//  Baisebudejie
//
//  Created by apple on 16/3/14.
//  Copyright © 2016年 youminuo. All rights reserved.
//

#import "BSBFriendController.h"
#import "BSBFriendTitleView.h"
#import "BSBAttentionTableController.h"
#import "BSBAttentionController.h"

@interface BSBFriendController ()
//内容包裹层
@property (weak, nonatomic) UIScrollView *contScroll;

@end

@implementation BSBFriendController

//包裹层的懒加载
- (UIScrollView *)contScroll
{
    if (_contScroll == nil)
    {
        UIScrollView *contscroll = [[UIScrollView alloc] init];
        contscroll.frame = CGRectMake(0, 64, self.view.width, self.view.height- 64);
        contscroll.contentSize = CGSizeMake(self.view.width * 2, 0);
        contscroll.showsHorizontalScrollIndicator = NO;
        contscroll.showsVerticalScrollIndicator = NO;
        contscroll.pagingEnabled = YES;
        contscroll.scrollEnabled = NO;
        self.contScroll = contscroll;
        [self.view addSubview:contscroll];
        
    }
    return _contScroll;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    修改背景颜色    
    self.view.backgroundColor = BSBBackgoundColor;
//    修改标题和导航条按钮
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithimage:@"friendsRecommentIcon" hightImage:@"friendsRecommentIcon-click" target:self action:@selector(itemDidClick)];
    [self setUptitleView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self setUpcontView];
    [self setUpattention];
}

#pragma mark - 设置titleView
- (void)setUptitleView
{
    BSBFriendTitleView *titleVC = [[BSBFriendTitleView alloc] init];
    __weak typeof(self) weakSelf = self;
    titleVC.btnBlcok = ^{
        CGFloat offsetX = weakSelf.contScroll.contentOffset.x;
//        [weakSelf.contScroll setContentOffset:CGPointMake((offsetX > 0 ? 0 : self.view.width), 0) animated:YES];
        weakSelf.contScroll.contentOffset = CGPointMake((offsetX > 0 ? 0 : self.view.width), 0);
    };
    titleVC.bounds = CGRectMake(0, 0, 100, 30);
    self.navigationItem.titleView = titleVC;
}

#pragma mark - 订阅界面
- (void)setUpcontView
{
//  设置关注层的容器
    UIView *attentionView = [[UIView alloc] init];
    attentionView.frame = CGRectMake(0, 0, self.contScroll.width, self.contScroll.height);
    [self.contScroll addSubview:attentionView];
//    设置顶部搜索栏
    UISearchBar *seatch = [[UISearchBar alloc] init];
    seatch.frame = CGRectMake(0, 0, attentionView.width, 40);
    seatch.placeholder = @"搜索";
//    seatch.barTintColor = BSBBackgoundColor;
    [seatch resignFirstResponder];
    [attentionView addSubview:seatch];
//  设置下面内容栏
    BSBAttentionTableController *atttable = [[BSBAttentionTableController alloc] init];
    atttable.view.frame = CGRectMake(0, CGRectGetMaxY(seatch.frame), attentionView.width, attentionView.height - CGRectGetMaxY(seatch.frame));
    [attentionView addSubview:atttable.view];
    [self addChildViewController:atttable];
}


- (void)setUpattention
{
//    设置关注页面
    BSBAttentionController *attentVC = [[BSBAttentionController alloc] init];
    attentVC.view.frame = CGRectMake(self.view.width, 0, self.contScroll.width, self.contScroll.height);
    [self.contScroll addSubview:attentVC.view];
    [self addChildViewController:attentVC];
}

- (void)itemDidClick
{
    
}

@end
